/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jifAdministraImpuestos.java
 *
 * Created on 15-sep-2011, 8:46:14
 */

package Impuestos;

import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.Utiles_Tabla;
import java.awt.Frame;
import java.util.List;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import suministros.ejb30.TO.ImpuestoTO;

/**
 *
 * @author Luis_Angel
 */
public class jifAdministraImpuestos extends javax.swing.JInternalFrame {

    private JTableBinding jTableBinding;
    private List<ImpuestoTO> lista;
    private BindingGroup bindingGroup;

    /** Creates new form jifAdministraImpuestos */
    public jifAdministraImpuestos() {
        initComponents();
        llenaTabla();
    }

    public void llenaTabla() {
        try {
            lista = GestionPedidosDelegate.getInstance().getListaImpuestos();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        this.bindingGroup = new BindingGroup();
        this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.lista, this.jtImpuestos);

        JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcion_corta}"));

        columnBinding0.setColumnName("Descripcion Corta");
        columnBinding0.setColumnClass(String.class);
        columnBinding0.setEditable(false);

        JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcion_larga}"));

        columnBinding1.setColumnName("Descripcion Larga");
        columnBinding1.setColumnClass(String.class);
        columnBinding1.setEditable(false);

        JTableBinding.ColumnBinding columnBinding4_1 = this.jTableBinding.addColumnBinding(ELProperty.create("${cuenta_debe}"));

        columnBinding4_1.setColumnName("Cta Debe");
        columnBinding4_1.setColumnClass(String.class);
        columnBinding4_1.setEditable(false);

        JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${cuenta_haber}"));

        columnBinding4.setColumnName("Cta Haber");
        columnBinding4.setColumnClass(String.class);
        columnBinding4.setEditable(false);

        JTableBinding.ColumnBinding columnBinding4_2 = this.jTableBinding.addColumnBinding(ELProperty.create("${efecto}"));

        columnBinding4_2.setColumnName("Efecto");
        columnBinding4_2.setColumnClass(String.class);
        columnBinding4_2.setEditable(false);

        this.bindingGroup.addBinding(this.jTableBinding);
        this.bindingGroup.bind();

        int[] porcentajes = {20, 35, 15, 15,15};
        try {
            // MiTablePrint.autoSizeTableColumns(jtCuentas);
            Utiles_Tabla.definirAnchoColumnasJTable(this.jtImpuestos, porcentajes);
        } catch (Exception ex) {
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtImpuestos = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jbCancelar = new javax.swing.JButton();
        jbEliminar = new javax.swing.JButton();
        jbEditar = new javax.swing.JButton();
        jbEditar1 = new javax.swing.JButton();

        setTitle("Administracion de Impuestos");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Lista de Impuestos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 11), new java.awt.Color(0, 0, 172))); // NOI18N

        jtImpuestos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Descripcion Corta", "Descripcion Larga", "Cta Debe", "Cta Haber", "Efecto"
            }
        ));
        jScrollPane1.setViewportView(jtImpuestos);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 569, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Operaciones", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 11), new java.awt.Color(0, 0, 170))); // NOI18N

        jbCancelar.setFont(new java.awt.Font("Arial", 1, 11));
        jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16nuvola/actions/exit.png"))); // NOI18N
        jbCancelar.setMnemonic('C');
        jbCancelar.setText("SALIR");
        jbCancelar.setToolTipText("Cancelar la Operacion");
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });
        jbCancelar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbCancelarKeyPressed(evt);
            }
        });

        jbEliminar.setFont(new java.awt.Font("Arial", 1, 11));
        jbEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/remove.png"))); // NOI18N
        jbEliminar.setMnemonic('A');
        jbEliminar.setText("ELIMINAR");
        jbEliminar.setToolTipText("Registrar el Comprobante");
        jbEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEliminarActionPerformed(evt);
            }
        });
        jbEliminar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbEliminarKeyPressed(evt);
            }
        });

        jbEditar.setFont(new java.awt.Font("Arial", 1, 11));
        jbEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/edit.png"))); // NOI18N
        jbEditar.setText("EDITAR");
        jbEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEditarActionPerformed(evt);
            }
        });

        jbEditar1.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        jbEditar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/document_new.png"))); // NOI18N
        jbEditar1.setText("NUEVO");
        jbEditar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEditar1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(173, 173, 173)
                .addComponent(jbEditar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbEditar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbCancelar)
                    .addComponent(jbEliminar)
                    .addComponent(jbEditar)
                    .addComponent(jbEditar1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 601, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 432, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed

        this.dispose();
}//GEN-LAST:event_jbCancelarActionPerformed

    private void jbCancelarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbCancelarKeyPressed

}//GEN-LAST:event_jbCancelarKeyPressed

    private void jbEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEliminarActionPerformed
        int filaElegida = this.jtImpuestos.getSelectedRow();
        if (filaElegida < 0) {
            Utiles_MensajesDialogo.mensajeError("Debe elegir un item!");
            this.jtImpuestos.requestFocus();
            return;
        }
        int res = javax.swing.JOptionPane.showConfirmDialog(this, "Esta seguro de realizar la operacion?",
                "Confirmar", javax.swing.JOptionPane.YES_NO_OPTION);
        if (res == javax.swing.JOptionPane.YES_OPTION) {
            ImpuestoTO impuesto = lista.get(this.jtImpuestos.convertRowIndexToModel(filaElegida));
            try {
                GestionPedidosDelegate.getInstance().eliminaImpuesto(impuesto.getId_impuesto());
                Utiles_MensajesDialogo.mensajeExito();
                llenaTabla();
            } catch (Exception ex) {
                ex.printStackTrace();
                Utiles_MensajesDialogo.mensajeFracaso("Ocurrio un error inesperado");
            }

        }

    }//GEN-LAST:event_jbEliminarActionPerformed

    private void jbEliminarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbEliminarKeyPressed

}//GEN-LAST:event_jbEliminarKeyPressed

    private void jbEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEditarActionPerformed

        int filaElegida = this.jtImpuestos.getSelectedRow();

        if (filaElegida < 0) {
            Utiles_MensajesDialogo.mensajeError("Debe elegir un item!");
            this.jtImpuestos.requestFocus();
            return;
        }
        ImpuestoTO impuesto = lista.get(this.jtImpuestos.convertRowIndexToModel(filaElegida));
        Frame frm = JOptionPane.getFrameForComponent((JInternalFrame) this);
        jdOperaImpuesto panel = new jdOperaImpuesto(frm, true, this);
        panel.setTitle("Datos de Impuesto : " + impuesto.getDescripcion_corta());
        panel.setLocationRelativeTo(null);
        panel.setDatos(impuesto);
        panel.setVisible(true);

        /* extracto_bancario = lista.get(this.jtExtractos.convertRowIndexToModel(filaElegida));
        if(!extracto_bancario.isCerrado()){
        opcion_guardar = 1;
        //habilitar(true);
        this.jtfSaldoInicial.setEnabled(true);
        this.jbGuardar.setEnabled(true);
        verDatos();
        } else
        Utiles_MensajesDialogo.mensajeAlerta("El item no puede ser editado");*/
}//GEN-LAST:event_jbEditarActionPerformed

    private void jbEditar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEditar1ActionPerformed
        Frame frm = JOptionPane.getFrameForComponent((JInternalFrame) this);
        jdOperaImpuesto panel = new jdOperaImpuesto(frm, true, this);
        panel.setTitle("Datos de Impuesto");
        panel.setLocationRelativeTo(null);
        panel.setVisible(true);
}//GEN-LAST:event_jbEditar1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbEditar;
    private javax.swing.JButton jbEditar1;
    private javax.swing.JButton jbEliminar;
    private javax.swing.JTable jtImpuestos;
    // End of variables declaration//GEN-END:variables

}
